-- upgrade test
SELECT CONTEXT_INFO()
GO

EXEC BABEL_GET_CONTEXT_INFO_WITH_PLP
GO

EXEC BABEL_GET_CONTEXT_INFO
GO

SELECT * FROM BABEL_CONTEXT_INFO_VIEW
GO

SELECT DISTINCT db_name(dbid), context_info FROM sys.sysprocesses WHERE spid = @@SPID
GO

SELECT context_info FROM sys.dm_exec_sessions WHERE session_id = @@SPID
GO

EXEC BABEL_SET_CONTEXT_INFO 0x1234567812345678
GO

EXEC BABEL_GET_CONTEXT_INFO_WITH_PLP
GO

EXEC BABEL_GET_CONTEXT_INFO
GO

SELECT * FROM BABEL_CONTEXT_INFO_VIEW
GO

SELECT DISTINCT db_name(dbid), context_info FROM sys.sysprocesses WHERE spid = @@SPID
GO

SELECT context_info FROM sys.dm_exec_sessions WHERE session_id = @@SPID
GO

-- test all data type

-- set date/datetime/xml, which should not be supported
DECLARE @context date = '2006-01-02'
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context datetime = '2006-01-02 15:04:05'
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context xml = '<root name="hello"></root>'
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set bit/decimal/numeric/money, which is supported in SQL Server but is not supported in Babelfish for now.
DECLARE @context bit = 1
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context decimal(38, 6) = 12345678123456781234567812345678.123456
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context decimal(38, 6) = 12345678123456781234567812345678.123456
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context money = 12345678.12345678
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set char/varchar directly, which should not be supported.
SET CONTEXT_INFO abc
GO

SELECT CONTEXT_INFO()
GO

-- NB: set char/varchar by declared parameter, which is not supported in SQL Server but is supported in Babelfish.
DECLARE @context varchar(10) = 'abc'
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set int/bigint/smallint/tinyint
DECLARE @context int = 2147483647
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context bigint = -9223372036854775808
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context smallint = -32768
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- NB: set tinyint, which is ff0000000000000000 in SQL Server but is 00ff00000000000000 in Babelfish.
DECLARE @context tinyint = 255
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set float/real
DECLARE @context float(53) = 12345678123456781234567812345678.123456
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context real = 12345678123456781234567812345678.123456
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set 0
SET CONTEXT_INFO 0
go

SELECT CONTEXT_INFO()
GO

-- set NULL, which should return error
SET CONTEXT_INFO NULL
GO

SELECT CONTEXT_INFO()
GO

DECLARE @context int
SET CONTEXT_INFO @context
GO

SELECT CONTEXT_INFO()
GO

-- set more than 128-byte hex constant
SET CONTEXT_INFO 0x123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567890
GO

SELECT CONTEXT_INFO()
GO

-- set 128-byte hex constant
SET CONTEXT_INFO 0x1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678
GO

SELECT CONTEXT_INFO()
GO

SELECT DISTINCT db_name(dbid), context_info FROM sys.sysprocesses WHERE spid = @@SPID
GO

SELECT context_info FROM sys.dm_exec_sessions WHERE session_id = @@SPID
GO

